﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;
namespace WebSite
{
    public partial class MP3List : PreBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindBlog();//首页中间位置
                BindBlogType();//MP3分类
                BindPVVideoOrder();//视频排行榜
                BindRecommandOrder();//推荐排行榜
                BindRecommand();//加载小编推荐
                BindAd();//加载广告
            }
        }

        #region 加载博客
        private void BindBlog()
        {
            //设置控件属性，从BasePage中得到
            PageConfig(BlogUPager);

            //List<Member> list = new List<Member();
            BlogHelper bhelper = new BlogHelper();
            Criteria c = new Criteria();
            Criteria c1 = new Criteria();

            //加载有效的
            c.Add(CriteriaType.Equals, "Flag", 0);
            c.Add(CriteriaType.Equals, "BlogBigType", "MP3");

            BlogUPager.ItemCount = bhelper.QueryBlogCountBySearch(c);

            // 以下的值从BasePage中得到
            BlogUPager.UrlFormat = UrlFormat;
            //BlogUPager.PrefixText = GetPreFixText(BlogUPager);


            string[] fields = new string[] { "ID", "BlogBigType", "BlogTypeName", "IsIndex", "CompanyID", "BlogTypeID", "Title", "BlogContent", "UsersID", "NickName", "PVCount", "ReplyCount", "RecommandCount", "HasPic", "Flag", "CreateDate" };

            DataTable dt = new DataTable();
            dt = bhelper.QueryBlogBySearchToTable(c, new Order[] { new Order("CreateDate", OrderMode.Desc) }, BlogUPager.Begin - 1, BlogUPager.Count, fields);
            dt.Columns.Add(new DataColumn("strBlogContent"));
            dt.Columns.Add(new DataColumn("contentvisible"));
            dt.Columns.Add(new DataColumn("strHasPic"));
            dt.Columns.Add(new DataColumn("strVideoPic"));
            dt.Columns.Add(new DataColumn("companyname"));//小组

            int index = 1;
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    //截取内容
                    string blogcontent = Server.HtmlDecode(dr["BlogContent"] + "");
                    //将内容中的html代码去掉
                    blogcontent = Tools.NoHTML(blogcontent);
                    string strblogcontent = Tools.GetFirstString(blogcontent, 160);
                    if (strblogcontent != "")
                    {
                        string userid = dr["UsersID"] + "";
                        //加载头像
                        UsersHelper uhelper = new UsersHelper();
                        Users ubloginfo = uhelper.GetUsers(userid);
                        string headphoto = ubloginfo.SmallHeadImage;
                        if (!string.IsNullOrEmpty(headphoto))
                        {
                            dr["strBlogContent"] = "<p class=\"post_item_summary\" ><a href=\"u/" + userid + ".aspx\" target=\"_blank\"><img align=\"left\" width=\"48\" height=\"48\"  class=\"pfs\" src=\"" + headphoto + "\" alt=\"\"/></a>" + strblogcontent + "</p>";
                        }
                        else
                        {
                            dr["strBlogContent"] = "<p class=\"post_item_summary\" ><a href=\"u/" + userid + ".aspx\" target=\"_blank\"><img align=\"left\" width=\"48\" height=\"48\"  class=\"pfs\" src=\"images/morentouxiang.jpg\" alt=\"\"/></a>" + strblogcontent + "</p>";
                        }
                    }

                    //判断是否存在图片
                    string haspic = dr["haspic"] + "";
                    if (haspic == "1")
                    {
                        dr["strHasPic"] = "<img src=\"images/smallpic.jpg\" alt=\"此创作包含图片\"/>";
                    }
                    else
                    {
                        dr["strHasPic"] = "";
                    }

                    //string blogbigtype = dr["BlogBigType"] + "";
                    //if (blogbigtype == "视频")
                    //{
                    //    dr["strVideoPic"] = "<img src=\"images/smallvideo.jpg\" alt=\"视频\"/>";
                    //}
                    //else if (blogbigtype.ToLower() == "mp3")
                    //{
                    //    dr["strVideoPic"] = "<img src=\"images/mp3.png\" alt=\"mp3\"/>";
                    //}
                    //else
                    //{
                    //    dr["strVideoPic"] = "";
                    //}

                    string blogbigtype = dr["BlogBigType"] + "";
                    if (blogbigtype == "视频")
                    {
                        dr["strVideoPic"] = "<img src=\"images/smallvideo.jpg\" alt=\"视频\"/>";
                        dr["BlogBigType"] = "<a href=\"VideoList.aspx\" target=\"_blank\"><font color=\"#729830\">" + blogbigtype + "</font></a>";
                    }
                    else if (blogbigtype.ToLower() == "mp3")
                    {
                        dr["strVideoPic"] = "<img src=\"images/mp3.png\" alt=\"mp3\"/>";
                        dr["BlogBigType"] = "<a href=\"MP3List.aspx\" target=\"_blank\"><font color=\"#729830\">" + blogbigtype + "</font></a>";
                    }
                    else
                    {
                        dr["strVideoPic"] = "";
                        dr["BlogBigType"] = "<a href=\"TextList.aspx\" target=\"_blank\"><font color=\"#729830\">" + blogbigtype + "</font></a>";
                    }

                    string blogtypename = dr["BlogTypeName"] + "";
                    string blogtypeid = dr["BlogTypeID"] + "";
                    dr["BlogTypeName"] = "<a href=\"cate/" + blogtypeid + ".aspx\" target=\"_blank\"><font color=\"#729830\">" + blogtypename + "</font></a>";
                    //加载小组
                    string companyid = dr["CompanyID"] + "";
                    if (!string.IsNullOrEmpty(companyid) && companyid != "0")
                    {
                        Companys cinfo = new Companys();
                        CompanysHelper chelper = new CompanysHelper();
                        cinfo = chelper.GetCompanys(companyid);
                        dr["companyname"] = "小组：" + cinfo.CompanyName;
                    }
                    else
                    {
                        dr["companyname"] = "";
                    }
                    index++;
                }
            }

            rptBlog.DataSource = dt;
            rptBlog.DataBind();
        }
        #endregion

        #region 加载分类
        private void BindBlogType()
        {
            BlogHelper bhelper = new BlogHelper();
            DataSet ds = bhelper.GetBlogTypeCount("MP3");

            rptBlogType.DataSource = ds;
            rptBlogType.DataBind();
        }
        #endregion

        #region 加载视频排行榜
        private void BindPVVideoOrder()
        {
            BlogHelper bhelper = new BlogHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "Flag", 0);
            c.Add(CriteriaType.Equals, "BlogBigType", "MP3");

            string[] fields = new string[] { "ID", "BlogBigType", "HasPic", "Title", "UsersID", "PVCount", "Flag", "CreateDate" };
            DataTable dtpvBlog = bhelper.QueryBlogBySearchToTable(c, new Order[] { new Order("PVCount", OrderMode.Desc) }, 0, 15, fields);

            DataColumn dcTitle = new DataColumn("strTitle");
            dtpvBlog.Columns.Add(dcTitle);
            dtpvBlog.Columns.Add(new DataColumn("strHasPic"));
            dtpvBlog.Columns.Add(new DataColumn("strVideoPic"));

            if (dtpvBlog != null && dtpvBlog.Rows.Count > 0)
            {
                foreach (DataRow dr in dtpvBlog.Rows)
                {
                    string title = dr["title"] + "";
                    string strtitle = "";
                    strtitle = Tools.GetFirstString(title, 26);
                    dr["strTitle"] = strtitle;

                    //判断是否存在图片
                    string haspic = dr["haspic"] + "";
                    if (haspic == "1")
                    {
                        dr["strHasPic"] = "<img src=\"images/smallpic.jpg\" alt=\"此创作包含图片\"/>";
                    }
                    else
                    {
                        dr["strHasPic"] = "";
                    }

                    string blogbigtype = dr["BlogBigType"] + "";
                    if (blogbigtype == "视频")
                    {
                        dr["strVideoPic"] = "<img src=\"images/smallvideo.jpg\" alt=\"视频\"/>";
                    }
                    else if (blogbigtype.ToLower() == "mp3")
                    {
                        dr["strVideoPic"] = "<img src=\"images/mp3.png\" alt=\"mp3\"/>";
                    }
                    else
                    {
                        dr["strVideoPic"] = "";
                    }
                }
            }
            rptPVMP3Order.DataSource = dtpvBlog;
            rptPVMP3Order.DataBind();
        }
        #endregion

        #region 加载推荐排行榜
        private void BindRecommandOrder()
        {
            BlogHelper bhelper = new BlogHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "Flag", 0);
            c.Add(CriteriaType.Equals, "BlogBigType", "MP3");

            string[] fields = new string[] { "ID", "BlogBigType", "HasPic", "Title", "UsersID", "PVCount", "Flag", "CreateDate" };
            DataTable dtpvBlog = bhelper.QueryBlogBySearchToTable(c, new Order[] { new Order("RecommandCount", OrderMode.Desc) }, 0, 15, fields);

            DataColumn dcTitle = new DataColumn("strTitle");
            dtpvBlog.Columns.Add(dcTitle);
            dtpvBlog.Columns.Add(new DataColumn("strHasPic"));
            dtpvBlog.Columns.Add(new DataColumn("strVideoPic"));

            if (dtpvBlog != null && dtpvBlog.Rows.Count > 0)
            {
                foreach (DataRow dr in dtpvBlog.Rows)
                {
                    string title = dr["title"] + "";
                    string strtitle = "";
                    strtitle = Tools.GetFirstString(title, 26);
                    dr["strTitle"] = strtitle;

                    //判断是否存在图片
                    string haspic = dr["haspic"] + "";
                    if (haspic == "1")
                    {
                        dr["strHasPic"] = "<img src=\"images/smallpic.jpg\" alt=\"此创作包含图片\"/>";
                    }
                    else
                    {
                        dr["strHasPic"] = "";
                    }

                    string blogbigtype = dr["BlogBigType"] + "";
                    if (blogbigtype == "视频")
                    {
                        dr["strVideoPic"] = "<img src=\"images/smallvideo.jpg\" alt=\"视频\"/>";
                    }
                    else if (blogbigtype.ToLower() == "mp3")
                    {
                        dr["strVideoPic"] = "<img src=\"images/mp3.png\" alt=\"mp3\"/>";
                    }
                    else
                    {
                        dr["strVideoPic"] = "";
                    }
                }
            }

            rptRecommandOrder.DataSource = dtpvBlog;
            rptRecommandOrder.DataBind();
        }
        #endregion

        #region 加载小编推荐
        private void BindRecommand()
        {
            BlogHelper bhelper = new BlogHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "Flag", 0);
            c.Add(CriteriaType.Equals, "BlogBigType", "MP3");
            c.Add(CriteriaType.Equals, "IsRecommand", 1);

            string[] fields = new string[] { "ID", "BlogBigType", "HasPic", "Title", "UsersID", "Flag", "CreateDate" };
            DataTable dtpvBlog = bhelper.QueryBlogBySearchToTable(c, new Order[] { new Order("CreateDate", OrderMode.Desc) }, 0, 15, fields);

            DataColumn dcTitle = new DataColumn("strTitle");
            dtpvBlog.Columns.Add(dcTitle);
            dtpvBlog.Columns.Add(new DataColumn("strHasPic"));
            dtpvBlog.Columns.Add(new DataColumn("strVideoPic"));

            if (dtpvBlog != null && dtpvBlog.Rows.Count > 0)
            {
                foreach (DataRow dr in dtpvBlog.Rows)
                {
                    string title = dr["title"] + "";
                    string strtitle = "";
                    strtitle = Tools.GetFirstString(title, 26);
                    dr["strTitle"] = strtitle;

                    //判断是否存在图片
                    string haspic = dr["haspic"] + "";
                    if (haspic == "1")
                    {
                        dr["strHasPic"] = "<img src=\"images/smallpic.jpg\" alt=\"此创作包含图片\"/>";
                    }
                    else
                    {
                        dr["strHasPic"] = "";
                    }

                    string blogbigtype = dr["BlogBigType"] + "";
                    if (blogbigtype == "视频")
                    {
                        dr["strVideoPic"] = "<img src=\"images/smallvideo.jpg\" alt=\"视频\"/>";
                    }
                    else if (blogbigtype.ToLower() == "mp3")
                    {
                        dr["strVideoPic"] = "<img src=\"images/mp3.png\" alt=\"mp3\"/>";
                    }
                    else
                    {
                        dr["strVideoPic"] = "";
                    }
                }
            }

            rptRecommand.DataSource = dtpvBlog;
            rptRecommand.DataBind();
        }
        #endregion

        #region 加载广告
        private void BindAd()
        {
            AdPositionHelper adhelper = new AdPositionHelper();
            litAd30.Text = adhelper.BindSystemAd("30", 1);
            litAd31.Text = adhelper.BindSystemAd("31", 1);
            litAd32.Text = adhelper.BindSystemAd("32", 1);
            litAd33.Text = adhelper.BindSystemAd("33", 1);
        }
        #endregion
    }
}